/**
 * CS575 Software Design
 * Group 6
 * Group Members: Anthony Davidson, Kendra Scheesley, Lyndsey Whitman, Stephen Zakrewsky
 * Date: May 19, 2012
 * Main Author(s): Kendra Scheesley
 */

package edu.drexel.cs575.a3;

import java.io.File;
import java.util.Scanner;

public class ScaleConfigCollector {
	private String modelDisplay;
	private String modelPowerUnit;
	private String modelBill;
	
	ScaleConfigCollector(int modelNumber){
		try
		{
			Boolean lost  = new Boolean(true);
			
			//get config file
			Scanner scanner = new Scanner(new File("scaleConfig.txt"));
			
			//loop through values until the model number is found
			if (scanner != null)
			{
				while(lost)
				{
					while (scanner.hasNextLine())
					{
						String itemLine = scanner.nextLine();
						String[] itemArray = itemLine.split(",");
						
						if (Integer.parseInt(itemArray[0]) == modelNumber)
						{
							
							//call displayFactory to set appropriate display based on config file value
							modelDisplay=itemArray[1];
							
							//call powerUnitFactory to set appropriate display based on config file value
							modelPowerUnit=itemArray[2];
							
							//call printerType to set appropriate printer (if any)
							modelBill=itemArray[3];

							//found model number, stop while
							lost = false;
						}
					}
					
					if (lost)
					{
						throw new IllegalStateException("Model number not found");
					}
				}
			}
		}
		catch (Exception e)
		{
			System.out.println("Error loading file.");
		}

	}
	
	public String getPowerUnit(){
		return modelPowerUnit;
	}
	
	public String getDisplay(){
		return modelDisplay;
	}
	
	public String getBill(){
		return modelBill;
	}
}
